package com.sailorj.controller;

import com.sailorj.entity.TbLab;
import com.sailorj.service.TbLabService;
import com.sailorj.util.PageBean;
import com.sailorj.util.SysLoging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springLab
 * @description: 实验室管理
 * @author: huangshengjun
 * @create: 2020-04-19 16:07
 **/
@CrossOrigin  //后端解决跨域方法注解
@Controller
@RequestMapping("/lab") //访问的路径
public class TbLabController {

    @Autowired
    private TbLabService tbLabService;

    /**
     * restful风格实现
     * @return
     */
    @ResponseBody
    @SysLoging("添加实验室信息") //根据SysLoging的注解信息，进行方法的注释
    @RequestMapping(value = "/addLab",method = RequestMethod.POST) //restful风格
    public String addLab(TbLab lab){
        lab.setIsDelete(0);
         tbLabService.addLab(lab);
        return "";
    }

    @ResponseBody
    @SysLoging("根据id查询实验室信息")
    @RequestMapping(value = "/getLabById",method = RequestMethod.GET)
    public TbLab getLabById(int id){
        return tbLabService.getLabById(id);
    }

    @ResponseBody
    @SysLoging("获取实验室信息列表")
    @RequestMapping(value = "/getLabList",method = RequestMethod.GET)
    PageBean getLabList(@RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer size){
        return tbLabService.getLabList(page,size);
    }

    @ResponseBody
    @SysLoging("删除实验室信息")
    @RequestMapping(value = "/deleteLab",method = RequestMethod.DELETE)
    public String deleteLab(int id) {
        TbLab lab1 = tbLabService.getLabById(id);
        lab1.setIsDelete(1);
        tbLabService.updateLabById(lab1);
        return "";
    }

    @ResponseBody
    @SysLoging("更新实验室信息")
    @RequestMapping(value = "/updateLab",method = RequestMethod.PUT)
    public String updateLab(TbLab lab) {
        lab.setIsDelete(0);
        tbLabService.updateLabById(lab);
        return "";
    }
}
